<?php 
class Disciplina_Model extends CI_Model
{
	private $tbl = 'disciplina';
	
	public function __construct()
	{
		parent::__construct();
		$this->load->database();
	}

	public function get($pk = null){
		$this->load->database();

		if ($pk === null){
			$query = $this->db->get($this->tbl);

			return $query->result_array();

		}

		$query = $this->db->get_where($this->tbl, array('codigo' => $pk));

		return $query->row_array();
	}

	public function define_disciplina(){

		$data = array(
				'codigo' => $this->input->post('codigo'),
				'nome'  => $this->input->post('nome'),
				'tipo'  => $this->input->post('tipo'),
				'creditos'  => $this->input->post('creditos')
		);

		return $this->db->insert($this->tbl, $data);
	}
	
	public function update_disciplina(){
	
		$data = array(
				'codigo' => $this->input->post('codigo'),
				'nome'  => $this->input->post('nome'),
				'tipo'  => $this->input->post('tipo'),
				'creditos'  => $this->input->post('creditos')
				);
		
		$this->db->where('codigo',$this->input->post('codigo_bd'));
		
		return $this->db->update($this->tbl, $data);
	}
	

	public function apaga ($pk){
		$this->db->delete($this->tbl ,array('codigo' => $pk));
	}

	public function get_paged_list($limit = 10, $offset = 0){
		$this->db->order_by('codigo','asc');
		return $this->db->get($this->tbl, $limit, $offset);
	}

	function get_by($field, $data){
		$this->db->where($field, $data);
		return $this->db->get($this->tbl);
	}
}
?>